﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
    <meta charset='UTF-8'>
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no,email=no" name="format-detection" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
    <link href="../Content/alipay/alipay.css" type="text/css" rel="stylesheet" />
    <link href="../Content/alipay/amui-demo_files/toast.css" type="text/css" rel="stylesheet" />
    <link href="../Content/alipay/button.css" type="text/css" rel="stylesheet" />
    <link href="../Content/alipay/amui-demo_files/dialog.css" type="text/css" rel="stylesheet" />
    <link href="../Content/alipay/amui-demo_files/button-group.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="../Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../Scripts/extensions/base.js"></script>
    <script type="text/javascript" src="../Content/alipay/amui-demo_files/amui.js"></script>
</head>
<body>
    <div data-role="page">
        <div data-role="content" style="background-color:#EFEFF4;padding-top:15px;">
                <div class="am-list-body">
                    <div class="am-list" am-mode="flat chip form">
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-control">
                                <input type="text" placeholder="姓名" id="realName" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                        </div>
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-control">
                                <input type="text" placeholder="身份证号" id="idCard" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                        </div>
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-control">
                                <input type="text" placeholder="手机号" id="mobile" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                        </div>
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-label">验证码</div>
                            <div class="am-list-control">
                                <input type="text" id="validateCode" placeholder="输入短信校验码" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                            <div class="am-list-button">
                                <button type="button" id="phone" onclick="checkPhone()"></button>
                            </div>
                        </div>
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-control">
                                <input type="password" placeholder="登录密码" id="password" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                        </div>
                        <div class="am-list-item am-input-autoclear">
                            <div class="am-list-control">
                                <input type="password" placeholder="确认密码" id="password1" value="">
                            </div>
                            <div class="am-list-clear"><i class="am-icon-clear am-icon" am-mode="clear" style="visibility: hidden;"></i></div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="padding-left:15px;padding-right:15px;margin-top:15PX;">
                <button id="searchButton" type="button" class="am-button"onclick="CheckIDCard()" am-mode="blue disabled">注册</button>
            </div>
        </div>
    <div id="fuwu" style="display: block;font-family:STHeitiSC;font-size: 12px; margin-bottom: 15px; margin-left: 0px; width: 100%; text-align: center;   position: absolute; bottom: 0px;z-index:-1;">
        <div class="am-agreement am-ft-gray am-ft-sm">
            <p>
                本服务由大庆公安厅<br />江苏欧索软件有限公司提供技术支持
            </p>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            $("#phone").html("获取验证码");
            window.setInterval("checkButtonState()", 200);
        });
        function GetvalidateCode()
        {
            settime();
            var mobile = $("#mobile").val();
            var url = "../../CityService.Service/PoliceService.svc/GetvalidateCode";
            $.ajax(url, {
                type: 'Get',
                dataType: 'Json',
                data: {
                    mobile: mobile,
                },
                success: function () {

                },
                error: function () {
                }
            });
        }
        var countdown = 60;
    
        function settime() {
            if (countdown == 0) {
                $("#phone").attr("disabled", false);
                $("#phone").css("color", "#0af");
                $("#phone").html("获取验证码");
                countdown = 60;
                return;
            }
            else {
                $("#phone").attr("disabled", true);
                $("#phone").css("color","black");
                $("#phone").html(countdown + "秒后重发");
                countdown--;
            }
            setTimeout(function (){
                settime()
            }, 1000)
        }
        function getCookie(key) {
            var keyValues = document.cookie.split(";");
            for (var index = 0; index < keyValues.length; index++) {
                var keyValue = keyValues[index].split("=");
                if (keyValue[0].trim() == key)
                    return keyValue[1];
            }
            return null;
        }
        function checkpassword()
        {
            var password = $("#password").val();
            var password1 = $("#password1").val();
            if (password != password1) {
                alert("两次输入的密码不一致");
                return false;
            }
            else
            {
                return true;
            }
        }
        function Register() {
            if (checkpassword())
            {
                var type = getQueryStringByName("type");
                var realName = $("#realName").val();
                var idCard = $("#idCard").val();
                var mobile = $("#mobile").val();
                var validateCode = $("#validateCode").val();
                var password = $("#password").val();
                var openId = getCookie("openID");
                var url = "../../CityService.Service/PoliceService.svc/Register";
                $.ajax(url, {
                    type: 'Get',
                    dataType: 'Json',
                    data: {
                        realName: realName,
                        idCard: idCard,
                        mobile: mobile,
                        validateCode: validateCode,
                        password: password,
                        openId: openId
                    },
                    success: function (msg) {
                        var temp = JSON.parse(msg.d);
                        if (temp.succ == true) {
                            alert("注册成功");
                            document.cookie = "guid=" + temp.data.guid;
                            if (type == 1)
                            {
                                location.href = "AskQuestion.html";
                            }
                            else if (type == 2)
                            {
                                location.href = "MyConsulting.html";
                            }
                            location.href = "Homepage.html";
                        }
                        else
                        {
                            alert(temp.msg);
                        }
                    },
                    error: function () {
                    }
                });
            }
        }
        function CheckIDCard() {
            var idCard = $("#idCard").val();
            var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
            if (regIdCard.test(idCard)) {
                if (idCard.length == 18) {
                    var idCardWi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //将前17位加权因子保存在数组里
                    var idCardY = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2];
                    var idCardWiSum = 0;
                    for (var i = 0; i < 17; i++) {
                        idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
                    }
                    var idCardMod = idCardWiSum % 11;
                    var idCardLast = idCard.substring(17);
                    if (idCardMod == 2) {
                        if (idCardLast == "X" || idCardLast == "x") {
                            Register();
                        }
                        else {
                            alert("身份证号码错误！");
                        }
                    }
                    else {
                        //用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
                        if (idCardLast == idCardY[idCardMod])
                        {
                            Register();
                        }
                        else {
                            alert("身份证号码错误！");
                        }
                    }
                }
            }
            else
            {
                alert("身份证格式不正确!");
            }
        }
        function checkPhone()
        {
            var tel = $("#mobile").val(); //获取手机号
            var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
            //如果手机号码不能通过验证
            if (telReg == false) {
                alert("请正确输入手机号码");
                return false;
            }
            else
            {
                GetvalidateCode();
            }
        }
        function checkButtonState() {
            if ($("#realName").val() && $("#idCard").val() && $("#validateCode").val() && $("#password").val())
            { $("#searchButton").attr("am-mode", "blue"); }
            else
            {
                $("#searchButton").attr("am-mode", "blue disabled");
            }
        }
    </script>
</body>

</html>